package com.blog.controller;

import cn.dev33.satoken.annotation.SaCheckRole;
import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.blog.entity.Comment;
import com.blog.service.CommentService;
import com.blog.vo.CommentVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/api/admin/comments")
public class AdminCommentController {
    
    @Autowired
    private CommentService commentService;
    
    /**
     * 获取所有评论（分页）
     */
    @GetMapping
    public Page<CommentVO> getCommentList(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestParam(required = false) Integer status) {
        // 检查是否是管理员
        StpUtil.checkLogin();
        
        return commentService.getCommentList(pageNum, pageSize, status);
    }
    
    /**
     * 审核评论
     */
    @PutMapping("/{commentId}/review")
    public Boolean reviewComment(
            @PathVariable Long commentId,
            @RequestBody Map<String, Integer> body) {
        // 检查是否是管理员
        StpUtil.checkLogin();
        
        Integer status = body.get("status");
        if (status == null) {
            throw new IllegalArgumentException("状态不能为空");
        }
        
        return commentService.reviewComment(commentId, status);
    }
} 